#ifndef BUSINESSUSER_H
#define BUSINESSUSER_H

#include <IdGenerator/idgenerator.h>

#include <UserManager/usermanager.h>
#include <hv/Channel.h>
#include <protocol/protocol.h>
#include <map>

class BusinessUser
{
public:

    // 删除拷贝构造函数和拷贝赋值操作符
    BusinessUser(BusinessUser const&) = delete;
    BusinessUser& operator=(BusinessUser const&) = delete;
    // 提供一个全局唯一的接口
    static BusinessUser& getInstance() {
        static BusinessUser instance;
        return instance;
    }
    // connect a new user
    void newLoginUser(ID id, const hv::SocketChannelPtr& channel);
    // disconnect a user
    void disconnect(const hv::SocketChannelPtr& channel);

    // varify the valid of login message
    bool varifyUser(const std::string& account, const std::string& password);

    // receive message of friend reply
    void recvReplyOfFriendApply(std::shared_ptr<Protocol> protocol, const hv::SocketChannelPtr& channel);

    // receive apply of friend
    void recvApplyOfFriend(std::shared_ptr<Protocol> protocol, const hv::SocketChannelPtr& channel);

    // refresh user List
    void refreshUserList(std::shared_ptr<Protocol> protocol, const hv::SocketChannelPtr& channel);

    // get target user
    void ReplyGetTargetUser(std::shared_ptr<Protocol> protocol, const hv::SocketChannelPtr& channel);

    // erase Friend
    void eraseFriend(std::shared_ptr<Protocol> protocol, const hv::SocketChannelPtr& channel);

    // update avatar
    void recvUpdateAvatar(std::shared_ptr<Protocol> protocol, const hv::SocketChannelPtr& channel);

    User& getTargetUser(uint64_t id);
    User& getTargetUser(const std::string& account);

private:
    BusinessUser() = default;

    std::map<uint32_t, ID> channelID2userID;
};

#endif // BUSINESSUSER_H
